import * as layoutFetch from '../api/apiLayout'
import {findInArray, getHistory, getState, setState, setStateReducer} from "../util/uitls";
import {effects} from 'dva-no-router/saga'

const INIT_STATE = {
    sku: {
        selectTypes: {},
        selectTags: {},
        description: "",
        "id": "",
        "title": "",
        "shopId": "",
        "categoryFilterId": "",
        "nonpublic": false,
        "designImageId": "",
        "designImage": {
            "id": "",
            "designSourceImage": "",
            "width": "",
            "height": "",
            "fromIp": "",
            "fileSize": "",
            "hash": "",
            "designSmallImage": "",
            "designMediumImage": "",
            "designLargeImage": "",
            "designXLargeImage": "",
            "imageStorageId": "",
            "dpi": ""
        },
        "designItems": [
            {
                "id": "",
                "productId": "",
                "productColorId": "",
                "printTypeId": "",
                "activated": true,
                "price": "",
                "currency_id": 1,
                "products": [
                    {
                        "id": "",
                        "categoryId": "",
                        "category": {
                            "categoryName": ""
                        },
                        "productName": "",
                        "defaultProductColorId": 1,
                        "defaultPrintTypeId": 1,
                        "printSpecs": [
                            {
                                "id": 123,
                                "productId": 123,
                                "printTypeId": 1,
                                "printTypeName": "",
                                "printWidth": "",
                                "printHeight": "",
                                "printMinWidth": "",
                                "printMinHeight": "",
                                "canvasWidth": "0",
                                "canvasHeight": "0",
                                "canvasOffsetX": "0",
                                "canvasOffsetY": "0",
                                "additionalFee": 0
                            }
                        ],
                        "printCustomizations": [
                            {
                                "id": 0,
                                "designItemId": 0,
                                "productId": 0,
                                "printTypeId": 0,
                                "imagePositionX": "0",
                                "imagePositionY": "0",
                                "imageScaleX": "0",
                                "imageScaleY": "0",
                                "imageRepeatTypeId": 0,
                                "designImageId": 0,
                                "designImage": {
                                    "id": 0,
                                    "designSourceImage": "",
                                    "width": "",
                                    "height": "",
                                    "fromIp": "",
                                    "fileSize": "",
                                    "hash": "",
                                    "designSmallImage": "",
                                    "designMediumImage": "",
                                    "designLargeImage": "",
                                    "designXLargeImage": "",
                                    "source_image_sync": true,
                                    "xlarge_image_sync": true,
                                    "imageStorageId": 0,
                                    "dpi": 0
                                }
                            }
                        ],
                        "productColors": [
                            {
                                "productColorId": 3,
                                "productColorName": "橙",
                                "rgbCode": "#ff3333",
                                "productImage": [
                                    {
                                        "id": 0,
                                        "productSmallImage": "",
                                        "productMediumImage": "",
                                        "productLargeImage": "",
                                        "productXLargeImage": "",
                                        "imageStorageId": 0,
                                        "printTypeId": 0
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    }
}
const Map = require('lodash.map')
const namespace = 'designe'
const model_layout = {
    namespace,
    state: JSON.parse(JSON.stringify(INIT_STATE)),
    reducers: {
        setState: setStateReducer
    },
    effects: {
        * reset_state(actions, {call, put}) {
            yield setState({
                sku:  {
                    selectTypes: {},
                    selectTags: {},
                    description: "",
                    "id": "",
                    "title": "",
                    "shopId": "",
                    "categoryFilterId": "",
                    "nonpublic": false,
                    "designImageId": "",
                    "designImage": {
                        "id": "",
                        "designSourceImage": "",
                        "width": "",
                        "height": "",
                        "fromIp": "",
                        "fileSize": "",
                        "hash": "",
                        "designSmallImage": "",
                        "designMediumImage": "",
                        "designLargeImage": "",
                        "designXLargeImage": "",
                        "imageStorageId": "",
                        "dpi": ""
                    },
                    "designItems": [
                        {
                            "id": "",
                            "productId": "",
                            "productColorId": "",
                            "printTypeId": "",
                            "activated": true,
                            "price": "",
                            "currency_id": 1,
                            "products": [
                                {
                                    "id": "",
                                    "categoryId": "",
                                    "category": {
                                        "categoryName": ""
                                    },
                                    "productName": "",
                                    "defaultProductColorId": 1,
                                    "defaultPrintTypeId": 1,
                                    "printSpecs": [
                                        {
                                            "id": 123,
                                            "productId": 123,
                                            "printTypeId": 1,
                                            "printTypeName": "",
                                            "printWidth": "",
                                            "printHeight": "",
                                            "printMinWidth": "",
                                            "printMinHeight": "",
                                            "canvasWidth": "0",
                                            "canvasHeight": "0",
                                            "canvasOffsetX": "0",
                                            "canvasOffsetY": "0",
                                            "additionalFee": 0
                                        }
                                    ],
                                    "printCustomizations": [
                                        {
                                            "id": 0,
                                            "designItemId": 0,
                                            "productId": 0,
                                            "printTypeId": 0,
                                            "imagePositionX": "0",
                                            "imagePositionY": "0",
                                            "imageScaleX": "0",
                                            "imageScaleY": "0",
                                            "imageRepeatTypeId": 0,
                                            "designImageId": 0,
                                            "designImage": {
                                                "id": 0,
                                                "designSourceImage": "",
                                                "width": "",
                                                "height": "",
                                                "fromIp": "",
                                                "fileSize": "",
                                                "hash": "",
                                                "designSmallImage": "",
                                                "designMediumImage": "",
                                                "designLargeImage": "",
                                                "designXLargeImage": "",
                                                "source_image_sync": true,
                                                "xlarge_image_sync": true,
                                                "imageStorageId": 0,
                                                "dpi": 0
                                            }
                                        }
                                    ],
                                    "productColors": [
                                        {
                                            "productColorId": 3,
                                            "productColorName": "橙",
                                            "rgbCode": "#ff3333",
                                            "productImage": [
                                                {
                                                    "id": 0,
                                                    "productSmallImage": "",
                                                    "productMediumImage": "",
                                                    "productLargeImage": "",
                                                    "productXLargeImage": "",
                                                    "imageStorageId": 0,
                                                    "printTypeId": 0
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }, true)(namespace)
        },
        * set_sku_profile({payload}, {call, put}) {
            yield setState({
                sku: payload
            })(namespace)
        },
    },
    subscriptions: {
        setup({dispatch, history}) {
        },
    },
};

export default model_layout
